package Cantella::DJabberd::Web::Controller::Admin;

use base 'Reaction::UI::Controller';
use aliased 'Cantella::DJabberd::Web::UI::ViewPort::Static';
use Reaction::Class;

__PACKAGE__->config(namespace => 'admin');

sub base :Chained('/auth/authed') :PathPart('admin') :CaptureArgs(0) {
  my ($self, $c) = @_;
  unless( $c->current_user->check_role('Administrator') ) {
    $c->forward('/error_403');
    $c->detach;
  }
  $self->build_nav($c);
  $c->stash->{menu}->current_item('admin');
}

sub root :Chained('base') :PathPart('') :Args(0) {
  my ($self, $c) = @_;
  $self->push_viewport(Static, file_name => 'index');
}

sub build_nav {
  my ($self, $c) = @_;
  my $submenu = $c->stash->{submenu};
  $submenu->add_item('users', uri => "/admin/user");
  $submenu->add_item('roles', uri => "/admin/role");
  $submenu->add_item('jids',  uri => "/admin/jid");
  $submenu->add_item('vhosts', uri => "/admin/vhost");
  $submenu->add_item('groups', uri => "/admin/jabber_group");
  $submenu->add_item('messages', uri => "/admin/message");
}

1;
